package com.fenghongzhang.day005rxprem;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.Manifest;
import android.os.Bundle;
import android.util.Log;

import com.tbruyelle.rxpermissions2.Permission;
import com.tbruyelle.rxpermissions2.RxPermissions;

import io.reactivex.Observable;
import io.reactivex.functions.Consumer;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity";
    private RxPermissions rxPermissions = new RxPermissions(this);
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//        requestPermissions(new String[]{Manifest.permission.READ_SMS},100);


//         rxPermissions.request(Manifest.permission.READ_SMS,Manifest.permission.READ_EXTERNAL_STORAGE).subscribe(new Consumer<Boolean>() {
//             @Override
//             public void accept(Boolean aBoolean) throws Exception {
//                 Log.i(TAG, "accept: "+aBoolean);
//             }
//         });
        
         rxPermissions.requestEach(Manifest.permission.READ_SMS,Manifest.permission.READ_EXTERNAL_STORAGE).subscribe(new Consumer<Permission>() {
             @Override
             public void accept(Permission permission) throws Exception {
                 if(permission.granted){
                     Log.i(TAG, "accept: 同意");
                 }else if(permission.shouldShowRequestPermissionRationale){
                     Log.i(TAG, "accept: 不同意");
                 }else {
                     Log.i(TAG, "accept: 一直不同意");
                 }
             }
         });
        
    }


}
